<style lang="less">
    @import "./daqibodao.less";
</style>
<template>
  <div>
    <Row :gutter=2 style="background-color: rgb(77, 185, 246);">
      <Col span="2" v-if="hasPermission">
        <Button :loading="exportLoading" @click="downloadIDSTemplate">
          IDS模板下载
        </Button>
      </Col>
      <Col span="2" v-if="hasPermission">
        <Upload :action= "baseUrl + '/expands/daqibodao/upLoadIDS'"
                :show-upload-list="false"
                :before-upload="handleBeforeUpload"
                :on-success="handleSuccess"
        >
          <Button>IDS数据上传</Button>
        </Upload>
      </Col>
      <Col :span="hasPermission ? 3 : 4">
        <Button :loading="exportLoading" @click="queryIDSDatas">集团IDS数据确认</Button>
      </Col>
      <!--<Col span="2">
        <Date-picker disabled v-model="idsDate" type="date" placement="bottom-end" placeholder="选择日期"></Date-picker>
      </Col>-->
      <Col span="2" class="select-date">
        第一日期选择：
      </Col>
      <Col span="2">
        <Date-picker type="date" :disabled="isDisabledDatePicker" v-model="date1" :options="options" @on-change="(date) => {changeDate(date, 1)}" placement="bottom-end" placeholder="选择日期"></Date-picker>
      </Col>
      <Col span="2" class="select-date">
        第二日期选择：
      </Col>
      <Col span="2">
        <Date-picker type="date" :disabled="isDisabledDatePicker" v-model="date2" :options="options" @on-change="(date) => {changeDate(date, 2)}" placement="bottom-end" placeholder="选择日期"></Date-picker>
      </Col>
      <Col span="2" class="select-date">
        第三日期选择：
      </Col>
      <Col span="2">
        <Date-picker type="date" :disabled="isDisabledDatePicker" v-model="date3" :options="options" @on-change="(date) => {changeDate(date, 3)}" placement="bottom-end" placeholder="选择日期"></Date-picker>
      </Col>
      <Col :span="hasPermission ? 3 : 4">
        <Button icon="ios-search" :loading="exportLoading" :disabled="isDisabledDatePicker" @click="innerQueryDates">确认查询</Button>
      </Col>
      <Col span="2">
        <Button icon="md-download" :disabled="isDisabledDatePicker" :loading="exportLoading" @click="exportExcel">数据导出</Button>
      </Col>
    </Row>
    <Row class="margin-top-10">
      <Table
        stripe
        border
        :height="(tableData && tableData.length > 0) ? 510 : 0"
        :loading="exportLoading"
        :highlight-row="true"
        ref="currentRowTable"
        :columns="tableTitle" :data="tableDataShow"
        :disabled-hover="true"
      ></Table>
      <div v-if="tableData && tableData.length > 0" style="margin: 10px;overflow: hidden">
        <div style="float: right;">
          <Page :total="tableData.length" :page-size="pageSize" :current="page" show-sizer show-elevator show-total @on-change="changePage" @on-page-size-change="pagesize"></Page>
        </div>
      </div>
    </Row>
  </div>
</template>
<script>
import excel from '@/libs/excel'
import {judgeIDSPermission, queryIDSDatas, innerQueryDates, queryDates} from '@/api/expands/daqibodao/daqibodao'
import util from '@/utils/index'
import config from '@/config'
export default {
  name: 'daqibodao',
  data () {
    return {
      baseUrl: config.ajax.baseURL,
      hasPermission: false,
      isDisabledDatePicker: true,
      idsDate: '',
      date1: '',
      date2: '',
      date3: '',
      options: {
        disabledDate (date) {
          return Date.now() - date.valueOf() <= 0
        }
      },
      exportLoading: false,
      tableTitle: [
        {
          title: '开始时间',
          key: 'starttime',
          width: 100,
          align: 'center',
          tooltip: true
        },
        {
          title: '整治批次',
          key: 'batch',
          width: 100,
          align: 'center',
          tooltip: true
        },
        {
          title: '地市',
          key: 'city',
          width: 100,
          align: 'center',
          tooltip: true,
          filters: [
            {
              label: '保定',
              value: '保定'
            },
            {
              label: '沧州',
              value: '沧州'
            },
            {
              label: '承德',
              value: '承德'
            },
            {
              label: '邯郸',
              value: '邯郸'
            },
            {
              label: '衡水',
              value: '衡水'
            },
            {
              label: '廊坊',
              value: '廊坊'
            },
            {
              label: '秦皇岛',
              value: '秦皇岛'
            },
            {
              label: '石家庄',
              value: '石家庄'
            },
            {
              label: '唐山',
              value: '唐山'
            },
            {
              label: '邢台',
              value: '邢台'
            },
            {
              label: '雄安新区',
              value: '雄安新区'
            },
            {
              label: '张家口',
              value: '张家口'
            }
          ],
          // filterMultiple: false,
          filterMethod (value, row) {
            return row.city === value
          }
        },
        {
          title: '区县',
          key: 'area',
          width: 100,
          align: 'center',
          tooltip: true
        },
        {
          title: '厂家',
          key: 'vendor',
          width: 100,
          align: 'center',
          tooltip: true,
          filters: [
            {
              label: '中兴',
              value: '中兴'
            },
            {
              label: '华为',
              value: '华为'
            },
            {
              label: '爱立信',
              value: '爱立信'
            },
            {
              label: '诺基亚',
              value: '诺基亚'
            }
          ],
          // filterMultiple: false,
          filterMethod (value, row) {
            return row.vendor === value
          }
        },
        {
          title: 'CGI',
          key: 'cgi',
          width: 100,
          align: 'center',
          tooltip: true
        },
        {
          title: '小区英文名称',
          key: 'cell_name_omc',
          width: 100,
          align: 'center',
          tooltip: true
        },
        {
          title: '小区经度',
          key: 'longitude',
          width: 100,
          align: 'center',
          tooltip: true
        },
        {
          title: '小区纬度',
          key: 'latitude',
          width: 100,
          align: 'center',
          tooltip: true
        },
        {
          title: 'ENODEB_ID',
          key: 'enodeb_id',
          width: 100,
          align: 'center',
          tooltip: true
        },
        {
          title: '数据来源',
          key: 'source_data',
          width: 100,
          align: 'center',
          tooltip: true
        },
        {
          title: '被检测次数',
          key: 'times_tested',
          width: 100,
          align: 'center',
          tooltip: true
        },
        {
          title: '基站名称',
          key: 'site_name',
          width: 100,
          align: 'center',
          tooltip: true
        },
        {
          title: '行政属性',
          key: 'adm_pro',
          width: 100,
          align: 'center',
          tooltip: true
        },
        {
          title: '频段细分（逻辑计算）',
          key: 'fre_band_detail',
          width: 100,
          align: 'center',
          tooltip: true
        },
        {
          title: '带宽',
          key: 'bandwidth',
          width: 100,
          align: 'center',
          tooltip: true
        },
        {
          title: '物理站ID（逻辑计算）',
          key: 'phy_site_id',
          width: 100,
          align: 'center',
          tooltip: true
        },
        {
          title: '物理扇区ID（逻辑计算）',
          key: 'phy_cell_id',
          width: 100,
          align: 'center',
          tooltip: true
        },
        {
          title: '物理扇区厚度',
          key: 'phy_cell_ply',
          width: 100,
          align: 'center',
          tooltip: true
        },
        {
          title: '物理扇区频段配置（逻辑计算）',
          key: 'phy_cell_band_config',
          width: 100,
          align: 'center',
          tooltip: true
        },
        {
          title: '日均流量（GB）',
          key: 'upoct',
          width: 100,
          align: 'center',
          tooltip: true
        },
        {
          title: '无线利用率',
          key: 'radio_use_rate',
          width: 100,
          align: 'center',
          tooltip: true
        },
        {
          title: '有效RRC连接平均数',
          key: 'effectiveconnmean',
          width: 100,
          align: 'center',
          tooltip: true
        },
        {
          title: 'MR覆盖率',
          key: 'rsrp_cover_rate',
          width: 100,
          align: 'center',
          tooltip: true
        },
        {
          title: '中心载频的信道号',
          key: 'earfcn',
          width: 100,
          align: 'center',
          tooltip: true
        },
        {
          title: '电子下倾角',
          key: 'downtilt_ele',
          width: 100,
          align: 'center',
          tooltip: true
        },
        {
          title: '机械下倾角',
          key: 'downtilt_mech',
          width: 100,
          align: 'center',
          tooltip: true
        },
        {
          title: '总下倾角',
          key: 'downtilt_all',
          width: 100,
          align: 'center',
          tooltip: true
        },
        {
          title: '方位角',
          key: 'dir',
          width: 100,
          align: 'center',
          tooltip: true
        },
        {
          title: '天线挂高',
          key: 'ant_higth',
          width: 100,
          align: 'center',
          tooltip: true
        },
        {
          title: '参考信号功率',
          key: 'reference_signal_power',
          width: 100,
          align: 'center',
          tooltip: true
        },
        {
          title: '小区PDSCH采用固定功率分配时的PA取值',
          key: 'pa',
          width: 100,
          align: 'center',
          tooltip: true
        },
        {
          title: '天线端口信号功率比(pb)',
          key: 'pb',
          width: 100,
          align: 'center',
          tooltip: true
        },
        {
          title: '特殊子帧模式',
          key: 'specialsfpatterns',
          width: 100,
          align: 'center',
          tooltip: true
        },
        {
          title: 'DATE1最强干扰',
          key: 'max_interfere_date1',
          width: 100,
          align: 'center',
          tooltip: true
        },
        {
          title: 'DATE2最强干扰',
          key: 'max_interfere_date2',
          width: 100,
          align: 'center',
          tooltip: true
        },
        {
          title: 'DATE3最强干扰',
          key: 'max_interfere_date3',
          width: 100,
          align: 'center',
          tooltip: true
        },
        {
          title: '是否受扰',
          key: 'is_interfere',
          width: 100,
          align: 'center',
          tooltip: true,
          filters: [
            {
              label: '是',
              value: '是'
            },
            {
              label: '否',
              value: '否'
            }
          ],
          // filterMultiple: false,
          filterMethod (value, row) {
            return row.is_interfere === value
          }
        },
        {
          title: '共站是否有FDD',
          key: 'is_fdd_enodeb',
          width: 100,
          align: 'center',
          tooltip: true,
          filters: [
            {
              label: '是',
              value: '是'
            },
            {
              label: '否',
              value: '否'
            }
          ],
          // filterMultiple: false,
          filterMethod (value, row) {
            return row.is_fdd_enodeb === value
          }
        },
        {
          title: '总倾角小于等于6度',
          key: 'downtilt_all_less6',
          width: 100,
          align: 'center',
          tooltip: true
        },
        {
          title: '机械倾角小于3度',
          key: 'downtilt_mech_less3',
          width: 100,
          align: 'center',
          tooltip: true
        },
        {
          title: '天线挂高大于30米',
          key: 'ant_higth_more30',
          width: 100,
          align: 'center',
          tooltip: true
        },
        {
          title: '日均流量小于20G',
          key: 'upoct_less20',
          width: 100,
          align: 'center',
          tooltip: true
        },
        {
          title: '覆盖率大于80%',
          key: 'rsrp_cover_rate_more80',
          width: 100,
          align: 'center',
          tooltip: true
        },
        {
          title: '降功率方案',
          key: 'power_reduction_plan',
          width: 100,
          align: 'center',
          tooltip: true
        },
        {
          title: '天馈调整建议',
          key: 'ant_adjust_sug',
          width: 100,
          align: 'center',
          tooltip: true
        },
        {
          title: '地市对功率调整意见',
          key: 'city_power_idea',
          width: 100,
          align: 'center',
          tooltip: true
        },
        {
          title: '天馈调整意见及进度',
          key: 'ant_adjust_idea_progress',
          width: 100,
          align: 'center',
          tooltip: true
        },
        {
          title: '功率修改日期',
          key: 'date_power_modify',
          width: 100,
          align: 'center',
          tooltip: true
        }
      ],
      tableData: [],
      tableDataShow: [],
      excelTitle: [
        '开始时间',
        '整治批次',
        '地市',
        '区县',
        '厂家',
        'CGI',
        '小区英文名称',
        '小区经度',
        '小区纬度',
        'ENODEB_ID',
        '数据来源',
        '被检测次数',
        '基站名称',
        '行政属性',
        '频段细分（逻辑计算）',
        '带宽',
        '物理站ID（逻辑计算）',
        '物理扇区ID（逻辑计算）',
        '物理扇区厚度',
        '物理扇区频段配置（逻辑计算）',
        '日均流量（GB）',
        '无线利用率',
        '有效RRC连接平均数',
        'MR覆盖率',
        '中心载频的信道号',
        '电子下倾角',
        '机械下倾角',
        '总下倾角',
        '方位角',
        '天线挂高',
        '参考信号功率',
        '小区PDSCH采用固定功率分配时的PA取值',
        '天线端口信号功率比(pb)',
        '特殊子帧模式',
        'DATE1最强干扰',
        'DATE2最强干扰',
        'DATE3最强干扰',
        '是否受扰',
        '共站是否有FDD',
        '总倾角小于等于6度',
        '机械倾角小于3度',
        '天线挂高大于30米',
        '日均流量小于20G',
        '覆盖率大于80%',
        '降功率方案',
        '天馈调整建议',
        '地市对功率调整意见',
        '天馈调整意见及进度',
        '功率修改日期'
      ],
      excelKey: [
        'starttime',
        'batch',
        'city',
        'area',
        'vendor',
        'cgi',
        'cell_name_omc',
        'longitude',
        'latitude',
        'enodeb_id',
        'source_data',
        'times_tested',
        'site_name',
        'adm_pro',
        'fre_band_detail',
        'bandwidth',
        'phy_site_id',
        'phy_cell_id',
        'phy_cell_ply',
        'phy_cell_band_config',
        'upoct',
        'radio_use_rate',
        'effectiveconnmean',
        'rsrp_cover_rate',
        'earfcn',
        'downtilt_ele',
        'downtilt_mech',
        'downtilt_all',
        'dir',
        'ant_higth',
        'reference_signal_power',
        'pa',
        'pb',
        'specialsfpatterns',
        'max_interfere_date1',
        'max_interfere_date2',
        'max_interfere_date3',
        'is_interfere',
        'is_fdd_enodeb',
        'downtilt_all_less6',
        'downtilt_mech_less3',
        'ant_higth_more30',
        'upoct_less20',
        'rsrp_cover_rate_more80',
        'power_reduction_plan',
        'ant_adjust_sug',
        'city_power_idea',
        'ant_adjust_idea_progress',
        'date_power_modify'
      ],
      pageSize: 10,
      page: 1
    }
  },
  methods: {
    downloadIDSTemplate () {
      window.open(this.baseUrl + '/expands/daqibodao/%E9%9B%86%E5%9B%A2ids%E6%95%B0%E6%8D%AE%E5%AF%BC%E5%85%A5%E6%A8%A1%E6%9D%BF.xlsx')
    },
    judgeIDSPermission () {
      this.$Loading.start()
      this.exportLoading = true
      judgeIDSPermission().then(res => {
        if (res.code === 0) {
          this.hasPermission = true
        } else if (res.code === 1) {
          console.log(res.msg)
        } else {
          this.$Message.info(res.msg)
        }
        this.$Loading.finish()
        this.exportLoading = false
      }).catch(err => {
        console.log(err)
        this.$Message.error(err)
        this.$Loading.finish()
        this.exportLoading = false
      })
    },
    handleBeforeUpload () {
      this.$Loading.start()
      this.exportLoading = true
    },
    handleSuccess (res, file) {
      this.$Loading.finish()
      this.exportLoading = false
      this.$Message.info(res.msg)
      console.log(file)
    },
    queryIDSDatas () {
      this.$Loading.start()
      this.exportLoading = true
      queryIDSDatas().then(res => {
        if (res.code === 0) {
          let IDSdate = res.data[0].starttime
          this.idsDate = IDSdate
          this.$Message.info('获取到的日期为' + IDSdate)
          if (util.compareTime(new Date(), new Date(IDSdate)) !== 0) {
            // this.$Message.info('数据未录入成功，请稍后查询！')
          } else {
            this.isDisabledDatePicker = false
            // this.$Message.info('数据导入成功，请输入日期后查询！')
          }
        } else {
          this.$Message.info(res.msg)
        }
        this.$Loading.finish()
        this.exportLoading = false
      }).catch(err => {
        console.log(err)
        this.$Message.error(err)
        this.$Loading.finish()
        this.exportLoading = false
      })
    },
    changeDate (date, formContent) {
      if (formContent === 1) {
        this.date1 = date
      }
      if (formContent === 2) {
        this.date2 = date
      }
      if (formContent === 3) {
        this.date3 = date
      }
    },
    checkDate () {
      if (!(this.date1 && this.date2 && this.date3)) {
        this.exportLoading = false
        this.$Message.error('请输入日期！')
        return false
      }
      if (!((new Date(this.date3).getTime() - new Date(this.date2).getTime() > 0) && (new Date(this.date2).getTime() - new Date(this.date1).getTime() > 0))) {
        this.exportLoading = false
        this.$Message.error('请按照日期大小顺序输入日期！')
        return false
      }
      return true
    },
    innerQueryDates () {
      this.$Loading.start()
      this.exportLoading = true
      if (!this.checkDate()) {
        return
      }
      innerQueryDates(
          {
            'date1': this.date1,
            'date2': this.date2,
            'date3': this.date3
          }
        ).then(res => {
          console.log(res)
          if (res.code === 0) {
            this.queryDates()
          } else {
            let that = this
            this.timer = setInterval(
              () => {
                that.queryDates()
              }, 1000 * 900
            )
            this.$Message.warning(res.msg)
          }
      }).catch(err => {
        console.log(err)
        this.$Message.error(err)
        this.$Loading.finish()
        this.exportLoading = false
      })
    },
    queryDates () {
      queryDates(
        {
          date1: this.date1,
          date2: this.date2,
          date3: this.date3
        }
      ).then(res => {
        console.log(res)
        if (res.code === 0) {
          this.tableData = res.data
          this.judgePage()
          clearInterval(this.timer)
          this.$Loading.finish()
          this.exportLoading = false
        } else {
          this.$Message.error(res.msg)
        }
      }).catch(err => {
        console.log(err)
        this.$Message.error(err)
        this.$Loading.finish()
        this.exportLoading = false
      })
    },
    judgePage () {
      this.page = 1
      // 初始化显示，小于每页显示条数，全显，大于每页显示条数，取前每页条数显示
      if (this.tableData.length < this.pageSize) {
        this.tableDataShow = this.tableData
      } else {
        this.tableDataShow = this.tableData.slice(0, this.pageSize)
      }
    },
    changePage (index) {
      // this.tableData = this.mockTableData1();
      // 当前页码
      this.page = index
      let _start = (index - 1) * this.pageSize
      let _end = index * this.pageSize
      this.tableDataShow = this.tableData.slice(_start, _end)
    },
    pagesize (index) {
      let _start = (this.page - 1) * index
      let _end = this.page * index
      this.tableData1 = this.ajaxtableData1.slice(_start, _end)
      // 当前展示条数
      this.pageSize = index
    },
    exportExcel () {
      if (this.tableData.length) {
        this.exportLoading = true
        const params = {
          title: this.excelTitle,
          key: this.excelKey,
          data: this.tableData,
          autoWidth: true,
          filename: '大气波导整治方案'
        }
        excel.export_array_to_excel(params)
        this.exportLoading = false
      } else {
        this.$Message.error('表格数据不能为空！')
      }
    }
  },
  created () {
      this.$emit('setHeader',
        {
          headerShow: true,
          headerTitle: '大气波导整治方案'
        }
      )
      this.judgeIDSPermission()
      this.$Message.config({
        duration: 3
      })
  },
  mounted () {

  }
}
</script>
